//
//  SignInViewController.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/27.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "SignInViewController.h"
#import "ShareView.h"

#import "SignInCollectionViewCell.h"
#import "UIImage+GradientColor.h"

#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "WeiboSDK.h"
#import "WXApi.h"

#import "UIImage+GradientColor.h"

@interface SignInViewController ()<TencentSessionDelegate, UICollectionViewDelegate, UICollectionViewDataSource,UITextViewDelegate>{
    UIImageView *giftIcon;
}

@property (nonatomic, strong) UIImageView *headView;
@property (nonatomic, strong) UILabel *valueLabel;
@property (nonatomic, strong) UILabel *noteLabel;
@property (nonatomic, assign) NSInteger currentDay;
@property (nonatomic, strong) ShareView *shareView;
@property (nonatomic, copy) NSString *shareId;
@property (nonatomic, copy) NSString *shareName;
@property (nonatomic, copy) NSString *shareLink;

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *dataArray;

@property (nonatomic, strong) TencentOAuth *tencentOAuth;

@property (nonatomic, strong) UIView *commentView;
@property (nonatomic, strong) NSString *appraiseId;

@property (nonatomic, assign) NSInteger shareType;

@end

@implementation SignInViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
    self.navigationController.navigationBarHidden = YES;
    [kNotificationCenter addObserver:self selector:@selector(shareSuccess) name:@"WechatShare" object:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [kNotificationCenter removeObserver:self name:@"WechatShare" object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.dataArray = [NSMutableArray array];
    [self setTopUI];
    [self setCollectionView];
    [self setShareUI];
    [self getData];
    
}

- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setTopUI {
    UIImage *bgImg = [UIImage gradientColorImageFromColors:@[REXADECIMALCOLOR(@"#ff1162"),REXADECIMALCOLOR(@"#fe4e4e")] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(SCREEN_WIDTH, ScreenX375(100) + STATUS_BAR_HEIGHT)];
    UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(100) + STATUS_BAR_HEIGHT)];
    bgView.image = bgImg;
    [self.view addSubview:bgView];
    
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, STATUS_BAR_HEIGHT, ScreenX375(44), ScreenX375(40))];
    [backBtn setImage:ImageWithName(@"返回2") forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
    self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(20), ScreenX375(40) + STATUS_BAR_HEIGHT, ScreenX375(37), ScreenX375(37))];
    self.headView.clipsToBounds = YES;
    self.headView.layer.cornerRadius = ScreenX375(18.5);
    [self.headView sd_setImageWithURL:[NSURL URLWithString:kNSUDefaultReadKey(@"pic")] placeholderImage:nil options:SDWebImageRetryFailed];
    [self.view addSubview:self.headView];
    
    UILabel *valueNote = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(68), ScreenX375(40) + STATUS_BAR_HEIGHT, ScreenX375(60), ScreenX375(14))];
    valueNote.text = @"我的虾币:";
    valueNote.textColor = REXADECIMALCOLOR(@"#ffffff");
    valueNote.font = Kfont(12);
    [self.view addSubview:valueNote];
    
    self.valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(128), ScreenX375(35) + STATUS_BAR_HEIGHT, ScreenX375(100), ScreenX375(18))];
    self.valueLabel.textColor = REXADECIMALCOLOR(@"#ffffff");
    self.valueLabel.font = Kfont(18);
    self.valueLabel.text = @"900";
    [self.view addSubview:self.valueLabel];
    
    self.noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(150), ScreenX375(40) + STATUS_BAR_HEIGHT, ScreenX375(140), ScreenX375(14))];
    self.noteLabel.textColor = REXADECIMALCOLOR(@"#ffffff");
    self.noteLabel.font = Kfont(12);
    self.noteLabel.textAlignment = NSTextAlignmentRight;
    self.noteLabel.text = @"分享出去才是签到成功";
    [self.view addSubview:self.noteLabel];
    
    CGFloat margin = ScreenX375(24);
    for (int i = 0; i < 7; i++) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(68) + i * (margin + ScreenX375(20)), ScreenX375(63) + STATUS_BAR_HEIGHT, ScreenX375(20), ScreenX375(20))];
        label.layer.cornerRadius = ScreenX375(10);
        label.layer.masksToBounds = YES;
        label.text = [NSString stringWithFormat:@"%d",i+1];
        label.textColor = REXADECIMALCOLOR(@"#fe3e53");
        label.font = Kfont(11);
        label.textAlignment = NSTextAlignmentCenter;
        label.backgroundColor = REXADECIMALCOLOR(@"#ffffff");
        label.tag = 100 + i;
        [self.view addSubview:label];
        
        if (i == 6) {
            giftIcon = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(4.5), ScreenX375(4.5), ScreenX375(11), ScreenX375(11))];
            giftIcon.image = ImageWithName(@"礼物");
            [label addSubview:giftIcon];
        }
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(88) + i * ScreenX375(44), ScreenX375(73) + STATUS_BAR_HEIGHT, ScreenX375(24), 1)];
        line.tag = 200 + i;
        line.backgroundColor = REXADECIMALCOLOR(@"#ffffff");
        if (i != 6) {
            [self.view addSubview:line];
        }
    }
    
}

- (void)setCollectionView {
    UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.itemSize = CGSizeMake(ScreenX375(347), ScreenX375(360));
    flowLayout.minimumLineSpacing = 0;
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, ScreenX375(120) + STATUS_BAR_HEIGHT, SCREEN_WIDTH, ScreenX375(360)) collectionViewLayout:flowLayout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.showsVerticalScrollIndicator = NO;
    [_collectionView registerClass:[SignInCollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
    
    [self.view addSubview:_collectionView];
    
    [self getPro];
}

- (void)shareSuccess {
    NSDictionary *parameter = @{@"id":_shareId,@"userId":kNSUDefaultReadKey(@"userId")};
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@api/shareSuccess",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            [self signInClick];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)getShare {
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@api/share",REQUESTHEADER] andParameter:@{@"proId":self.appraiseId,@"userId":kNSUDefaultReadKey(@"userId"),@"type":@"3"} success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            self.shareId = [NSString stringWithFormat:@"%@",successResponse[@"data"][@"id"]];
            self.shareLink = [NSString stringWithFormat:@"%@",successResponse[@"data"][@"url"]];
            
            __weak __typeof(self) weakSelf = self;
            if (weakSelf.shareType == 0) {
                SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
                sendReq.bText = NO;
                sendReq.scene = 0;
                
                // 2.创建分享内容
                WXMediaMessage *message = [WXMediaMessage message];
                //分享标题
                message.title = @"虾拼";
                // 描述
                message.description = weakSelf.shareName;
                //分享图片,使用SDK的setThumbImage方法可压缩图片大小
                //                message.thumbData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMAGEHEADER,self.model.pics.firstObject]]];
                [message setThumbImage:[UIImage imageNamed:@"虾拼 logo"]];
                
                //创建多媒体对象
                WXWebpageObject *webObj = [WXWebpageObject object];
                // 点击后的跳转链接
                webObj.webpageUrl = weakSelf.shareLink;
                message.mediaObject = webObj;
                sendReq.message = message;
                [WXApi sendReq:sendReq];
            }else if (weakSelf.shareType == 1) {
                SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
                sendReq.bText = NO;
                sendReq.scene = 1;
                
                // 2.创建分享内容
                WXMediaMessage *message = [WXMediaMessage message];
                //分享标题
                message.title = @"虾拼";
                // 描述
                message.description = weakSelf.shareName;
                //分享图片,使用SDK的setThumbImage方法可压缩图片大小
                [message setThumbImage:[UIImage imageNamed:@"虾拼 logo"]];
                
                //创建多媒体对象
                WXWebpageObject *webObj = [WXWebpageObject object];
                // 点击后的跳转链接
                webObj.webpageUrl = weakSelf.shareLink;
                message.mediaObject = webObj;
                sendReq.message = message;
                [WXApi sendReq:sendReq];
            }else if (weakSelf.shareType == 2) {
                weakSelf.tencentOAuth = [[TencentOAuth alloc] initWithAppId:kQQAppKey andDelegate:weakSelf];
                
                NSString *url = weakSelf.shareLink;
                NSString *imageUrl = [NSString stringWithFormat:@"%@",IMAGEHEADER];
                
                QQApiNewsObject *share = [QQApiNewsObject objectWithURL:[NSURL URLWithString:url] title:@"虾拼" description:weakSelf.shareName previewImageURL:[NSURL URLWithString:imageUrl]];
                SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:share];
                
                //分享到qq
                [QQApiInterface sendReq:req];
            }else if (weakSelf.shareType == 3) {
                weakSelf.tencentOAuth = [[TencentOAuth alloc] initWithAppId:kQQAppKey andDelegate:weakSelf];
                
                NSString *url = weakSelf.shareLink;
                NSString *imageUrl = [NSString stringWithFormat:@"%@",IMAGEHEADER];
                
                QQApiNewsObject *share = [QQApiNewsObject objectWithURL:[NSURL URLWithString:url] title:@"虾拼" description:weakSelf.shareName previewImageURL:[NSURL URLWithString:imageUrl]];
                SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:share];
                
                //分享到qq
                [QQApiInterface SendReqToQZone:req];
            }else {
                //微博
                WBMessageObject *message = [WBMessageObject message];
                message.text = [NSString stringWithFormat:@"虾拼 %@  %@",weakSelf.shareName,weakSelf.shareLink];
                
                WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request];
                authRequest.redirectURI = kWeiboAppRedirectURL;
                authRequest.scope = @"all";
                
                WBSendMessageToWeiboRequest *sharerequest = [WBSendMessageToWeiboRequest requestWithMessage:message authInfo:authRequest access_token:nil];
                [WeiboSDK sendRequest:sharerequest];
            }
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)setShareUI {
    self.shareView = [[ShareView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - ScreenX375(130), SCREEN_WIDTH, ScreenX375(180))];
    __weak __typeof(self) weakSelf = self;
    self.shareView.wxClick = ^{
        weakSelf.shareType = 0;
        [weakSelf getShare];
    };
    self.shareView.wxGroupClick = ^{
        weakSelf.shareType = 1;
        [weakSelf getShare];
    };
    self.shareView.qqClick = ^{
        weakSelf.shareType = 2;
        [weakSelf getShare];
    };
    self.shareView.qqGroupClick = ^{
        weakSelf.shareType = 3;
        [weakSelf getShare];
    };
    self.shareView.wbClick = ^{
        weakSelf.shareType = 4;
        [weakSelf getShare];
    };
    [self.view addSubview:self.shareView];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - ScreenX375(152), SCREEN_WIDTH, ScreenX375(48))];
    titleLabel.text = @"分享赚虾币";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = KBlodfont(14);
    titleLabel.backgroundColor = REXADECIMALCOLOR(@"#f4f4f4");
    titleLabel.textColor = REXADECIMALCOLOR(@"#212121");
    [self.view addSubview:titleLabel];
}

- (void)getData {
    NSDictionary *parameter = @{@"userId":kNSUDefaultReadKey(@"userId")};
    [HttpManager postHttpRequestByGet:[NSString stringWithFormat:@"%@api/getSignIn",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            self.currentDay = [successResponse[@"data"][@"signCount"] integerValue];
            for (int i = 0; i < self.currentDay; i++) {
                UILabel *dayLabel = [self.view viewWithTag:100 + i];
                dayLabel.backgroundColor = REXADECIMALCOLOR(@"#fe3e52");
                dayLabel.layer.borderColor = REXADECIMALCOLOR(@"#ffbf00").CGColor;
                dayLabel.layer.borderWidth = 2;
                dayLabel.textColor = REXADECIMALCOLOR(@"#ffffff");
                
                if (i < self.currentDay - 1) {
                    UIView *line = [self.view viewWithTag:200 + i];
                    line.backgroundColor = REXADECIMALCOLOR(@"#ffbf00");
                }
            }
            if (self.currentDay == 7) {
                self->giftIcon.image = ImageWithName(@"礼物2");
            }else {
                self->giftIcon.image = ImageWithName(@"礼物");
            }
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)signInClick {
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@api/signIn",REQUESTHEADER] andParameter:@{@"userId":kNSUDefaultReadKey(@"userId"),@"proId":self.appraiseId} success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            [HttpManager showNoteMsg:@"签到成功"];
            self.currentDay++;
            for (int i = 0; i < self.currentDay; i++) {
                UILabel *dayLabel = [self.view viewWithTag:100 + i];
                dayLabel.backgroundColor = REXADECIMALCOLOR(@"#fe3e52");
                dayLabel.layer.borderColor = REXADECIMALCOLOR(@"#ffbf00").CGColor;
                dayLabel.layer.borderWidth = 2;
                dayLabel.textColor = REXADECIMALCOLOR(@"#ffffff");
                if (i < self.currentDay - 1) {
                    UIView *line = [self.view viewWithTag:200 + i];
                    line.backgroundColor = REXADECIMALCOLOR(@"#ffbf00");
                }
            }
            if (self.currentDay == 7) {
                self->giftIcon.image = ImageWithName(@"礼物2");
            }else {
                self->giftIcon.image = ImageWithName(@"礼物");
            }
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)getPro {
    NSDictionary *parameter = @{@"userId":kNSUDefaultReadKey(@"userId")};
    [HttpManager postHttpRequestByGet:[NSString stringWithFormat:@"%@api/signInPro",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            NSError *error = nil;
            for (NSDictionary *dic in successResponse[@"data"][@"list"]) {
                ChannelListModel *model = [[ChannelListModel alloc] initWithDictionary:dic error:&error];
                [self.dataArray addObject:model];
            }
            [self.collectionView reloadData];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _dataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SignInCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    cell.channelListModel = _dataArray[indexPath.row];
    ChannelListModel *model = _dataArray[indexPath.row];
    self.shareName = model.proName;
    self.appraiseId = model.Id;
    cell.concernClick = ^{
        [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@api/concern",REQUESTHEADER] andParameter:@{@"concernedId":model.userId,@"concernId":kNSUDefaultReadKey(@"userId")} success:^(id successResponse) {
            NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
            if ([status isEqualToString:@"200"]) {
                if ([model.isFollow integerValue]) {
                    model.isFollow = @"0";
                }else {
                    model.isFollow = @"1";
                }
                [self.collectionView reloadData];
            }else {
                [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
            }
        } andFailure:^(id failureResponse) {
            [HttpManager showFail];
        }];
    };
    cell.appraiseClick = ^{
        [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@api/zan",REQUESTHEADER] andParameter:@{@"proId":model.Id,@"userId":kNSUDefaultReadKey(@"userId"),@"type":@"0"} success:^(id successResponse) {
            NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
            if ([status isEqualToString:@"200"]) {
                if ([model.isZan integerValue]) {
                    model.isZan = @"0";
                    model.zanNum = [NSString stringWithFormat:@"%ld",[model.zanNum integerValue] - 1];
                }else {
                    model.isZan = @"1";
                    model.zanNum = [NSString stringWithFormat:@"%ld",[model.zanNum integerValue] + 1];
                }
                [self.collectionView reloadData];
            }else {
                [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
            }
        } andFailure:^(id failureResponse) {
            [HttpManager showFail];
        }];
    };
    cell.commentClick = ^{
        self.appraiseId = model.Id;
        [self showComment];
    };
    return cell;
}

- (void)close {
    [_commentView removeFromSuperview];
}

- (void)showComment {
    if (!_commentView) {
        _commentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _commentView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        
        UIView *commentBg = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(24), ScreenX375(210), SCREEN_WIDTH - ScreenX375(48), ScreenX375(194))];
        commentBg.backgroundColor = REXADECIMALCOLOR(@"#f5f5f5");
        commentBg.layer.cornerRadius = ScreenX375(8);
        commentBg.clipsToBounds = YES;
        [_commentView addSubview:commentBg];
        
        UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, ScreenX375(29), ScreenX375(29))];
        [closeBtn setImage:ImageWithName(@"关闭") forState:UIControlStateNormal];
        [closeBtn addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
        [commentBg addSubview:closeBtn];
        
        UITextView *commentText = [[UITextView alloc] initWithFrame:CGRectMake(ScreenX375(25), ScreenX375(23), SCREEN_WIDTH - ScreenX375(98), ScreenX375(105))];
        commentText.backgroundColor = [UIColor whiteColor];
        commentText.font = Kfont(14);
        commentText.layer.cornerRadius = ScreenX375(4);
        commentText.clipsToBounds = YES;
        commentText.text = @"写评论...";
        commentText.tag = 555;
        commentText.textColor = REXADECIMALCOLOR(@"#999999");
        commentText.delegate = self;
        [commentBg addSubview:commentText];
        
        UIImage *bgImg = [UIImage gradientColorImageFromColors:@[REXADECIMALCOLOR(@"#ff1162"),REXADECIMALCOLOR(@"#fe4e4e")] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(ScreenX375(103), ScreenX375(112))];
        UIButton *commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(112), ScreenX375(144), ScreenX375(103), ScreenX375(30))];
        [commitBtn setTitle:@"提交评论" forState:UIControlStateNormal];
        [commitBtn setTitleColor:REXADECIMALCOLOR(@"#ffffff") forState:UIControlStateNormal];
        commitBtn.titleLabel.font = Kfont(15);
        [commitBtn setBackgroundImage:bgImg forState:UIControlStateNormal];
        commitBtn.layer.cornerRadius = ScreenX375(15);
        commitBtn.layer.masksToBounds = YES;
        [commitBtn addTarget:self action:@selector(commitComment) forControlEvents:UIControlEventTouchUpInside];
        [commentBg addSubview:commitBtn];
    }
    [kKeyWindow addSubview:_commentView];
}

- (void)commitComment {
    UITextView *textView = [_commentView viewWithTag:555];
    if (textView.text.length == 0) {
        [HttpManager showNoteMsg:@"请输入评论内容"];
        return;
    }
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@api/appraisePro",REQUESTHEADER] andParameter:@{@"proId":_appraiseId,@"content":textView.text,@"userId":kNSUDefaultReadKey(@"userId")} success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            [HttpManager showNoteMsg:@"评论成功"];
            [self close];
            self.appraiseId = @"";
            textView.textColor = REXADECIMALCOLOR(@"#999999");
            textView.text = @"写评论...";
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

-(void)textViewDidBeginEditing:(UITextView *)textView{
    if (textView.tag == 555) {
        if ([textView.text isEqualToString:@"写评论..."]) {
            textView.textColor = [UIColor blackColor];
            textView.text = @"";
        }
    }
}

- (void)textViewDidEndEditing:(UITextView *)textView {
    if (textView.tag == 500) {
        if (textView.text.length < 1) {
            textView.textColor = REXADECIMALCOLOR(@"#999999");
            textView.text = @"写评论...";
        }
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
